home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / emulator / bsvc-1.000 / bsvc-1 / bsvc-1.0.4 / samples / Hector1600 / SignedMult.asm < prev    next >
Assembly Source File  |  1995-07-26  |  2KB  |  101 lines

  1. ;-----------------------------------------------------------------------------
  2. ; ECE463 Signed Multiply
  3. ;
  4. ; Coded by: Bradford W. Mott
  5. ;           September 5,1993
  6. ;-----------------------------------------------------------------------------
  7.  
  8.           .org 0000
  9.  
  10.           move #512,sp
  11.           move #0,r0            ; Init Loop Variable
  12.  
  13. loop:     cmp  #num_els,r0      ; Check to see if we're finished
  14.           bra  finished,.eq
  15.  
  16.           move [r0,data1],r8    ; Get the multiplicand
  17.           move [r0,data2],r9    ; Get the multiplier
  18.           jsr  multiply         ; multiply the two numbers
  19.  
  20.           move r0,r1
  21.           add  r1,r1
  22.           move r11,[r1,result]  ; Store the result 
  23.           move r10,[r1,result+1]
  24.  
  25.           inc  r0
  26.           bra  loop
  27.  
  28. finished: stop
  29.  
  30.  
  31. multiply: clr  r10              ; loProd
  32.           clr  r11              ; hiProd
  33.  
  34.           move #15,r12          ; Init the counter
  35.  
  36. mloop:    shr  r9               ; Shift the multiplier by one bit
  37.           bra  noadd,.cc        ; Was the bit a 0 or a 1?
  38.  
  39.           clc
  40.           addc r8,r11           ; hiProd:=BaddV(hiProd,mcnd,0,V)
  41.           bra  m1,.t
  42.  
  43. noadd:    add  #0,r12           ; clear V flag        
  44.  
  45. m1:       bra  flip1,.vs        
  46.  
  47.           clc
  48.           btst #0x8000,r11
  49.           bra  m2,.eq
  50.           sec
  51.           bra  m2,.t
  52.  
  53. flip1:    clc
  54.           btst #0x8000,r11
  55.           bra  m2,.ne
  56.           sec
  57.  
  58. m2:       ror  r11              ; hiProd := Bshr(hiProd,sign,C)
  59.           ror  r10              ; loProd := Bshr(loProd,C,C)
  60.  
  61.           dec  r12
  62.           bra  mloop,.ne
  63.  
  64.  
  65.           shr  r9
  66.           bra  noadd2,.cc
  67.  
  68.           not  r8
  69.           sec
  70.           addc r8,r11           ; hiProd := BaddV(hiPord,Bcom(mcnd),1,V)
  71.           bra  z1
  72.      
  73. noadd2:   add  #0,r12 
  74.  
  75. z1:       bra  flip2,.vs        
  76.  
  77.           clc
  78.           btst #0x8000,r11
  79.           bra  z2,.eq
  80.           sec
  81.           bra  z2,.t
  82.  
  83. flip2:    clc
  84.           btst #0x8000,r11
  85.           bra  z2,.ne
  86.           sec
  87.  
  88. z2:       ror  r11              ; hiProd := Bshr(hiProd,sign,C)
  89.           ror  r10              ; loProd := Bshr(loProd,C,C)
  90.  
  91.           rts                   ; That's All
  92.  
  93.  
  94.           .org  256
  95.  
  96. num_els:  .equ  4
  97. data1:    .word 0x0005,0x000A,0x00FF,0xFFFF
  98. data2:    .word 0x0005,0x0000,0xFFFF,0xFFFF
  99. result:   .rmw  num_els+num_els
  100.  
  101.